//
//  ZJStudyBookTableViewCell.m
//  LovingPartyBuilding
//
//  Created by ZJ on 2017/5/2.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJStudyBookTableViewCell.h"



@interface ZJStudyBookTableViewCell ()
/** 图书图片 */
@property (nonatomic, strong) UIImageView *imageview;

/** 题目 */
@property (nonatomic, strong) UILabel *titleLabel;
/** 简介 */
@property (nonatomic, strong) UILabel *abstract;
/** 主讲人 */
@property (nonatomic, strong) UILabel *speaker;
/** 点击量 */
@property (nonatomic, strong) UILabel *clickNumber;
/** 分割线 */
@property (nonatomic, strong) UILabel *underline;
@end

@implementation ZJStudyBookTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self.contentView addSubview:self.imageview];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.speaker];
        [self.contentView addSubview:self.abstract];
        [self.contentView addSubview:self.clickNumber];
        [self.contentView addSubview:self.underline];
        
        self.underline.sd_layout
        .bottomSpaceToView(self.contentView, 0)
        .leftSpaceToView(self.contentView, 0)
        .rightSpaceToView(self.contentView, 0)
        .heightIs(7.5 * [UIScreen zj_screenHScale]);
        
        self.imageview.sd_layout
        .topSpaceToView(self.contentView, 12 * [UIScreen zj_screenHScale])
        .leftSpaceToView(self.contentView, 12 * [UIScreen zj_screenWScale])
        .bottomSpaceToView(self.underline, 12 * [UIScreen zj_screenHScale])
        .widthIs(140 * [UIScreen zj_screenWScale]);
        
        self.titleLabel.sd_layout
        .topEqualToView(self.imageview)
        .leftSpaceToView(self.imageview, 8.5 * [UIScreen zj_screenWScale])
        .rightSpaceToView(self.contentView, 12 * [UIScreen zj_screenWScale])
        .heightIs([NSString heightWithTextFontSize:[UIFont titleTextFontSize]]);
        
        self.clickNumber.sd_layout
        .bottomEqualToView(self.imageview)
        .rightEqualToView(self.titleLabel)
        .widthIs(90 * [UIScreen zj_screenWScale])
        .heightIs([NSString heightWithTextFontSize:[UIFont subTitleTextFontSize]]);
        
        self.speaker.sd_layout
        .bottomEqualToView(self.clickNumber)
        .leftEqualToView(self.titleLabel)
        .heightRatioToView(self.clickNumber, 1)
        .rightSpaceToView(self.clickNumber, 0);
        
        
        self.abstract.sd_layout
        .topSpaceToView(self.titleLabel, 4 * [UIScreen zj_screenHScale])
        .leftEqualToView(self.titleLabel)
        .widthIs([UIScreen zj_screenWith] - (24 +8.5 + 140) * [UIScreen zj_screenWScale])
        .bottomSpaceToView(self.speaker, 4 * [UIScreen zj_screenHScale]);
    
    }
    return self;
}



#pragma mark - Setter
- (void)setModel:(ZJStudyRecommendModel *)model{
    _model = model;
    if ([model.IMAGEPHOTO_THUMBURL containsString:@"http:"]) {
        [self.imageview sd_setImageWithURL:[NSURL URLWithString:model.IMAGEPHOTO_THUMBURL] placeholderImage:PlaceholderImage];
    }else{
        [self.imageview sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BASEIMAGEURL,model.IMAGEPHOTO_THUMBURL]] placeholderImage:PlaceholderImage];
    }    self.titleLabel.text = model.NAME;
    self.abstract.text = model.COMMENT;
    
//    [self.abstract setLabelSpace:1 * [UIScreen zj_screenHScale]];
    
    self.abstract.sd_layout
    .topSpaceToView(self.titleLabel, 10 * [UIScreen zj_screenHScale])
    .leftEqualToView(self.titleLabel)
    .widthIs([UIScreen zj_screenWith] - (24 +8.5 + 140) * [UIScreen zj_screenWScale])
    .heightIs([self.abstract getLableSizeWithMaxWidth:self.abstract.width].height);
    
    [self.abstract updateLayout];
    
    self.speaker.text = [NSString stringWithFormat:@"悦读者 : %@", model.TEACHERSNAME];
    self.clickNumber.text = [NSString stringWithFormat:@"播放量 : %@", model.CLICKRATE];
    
}

- (void)setCollectModel:(ZJOptionalStudyModel *)collectModel{
    _collectModel = collectModel;
    
    if ([collectModel.IMAGEPHOTO_THUMBURL containsString:@"http:"]) {
        [self.imageview sd_setImageWithURL:[NSURL URLWithString:collectModel.IMAGEPHOTO_THUMBURL] placeholderImage:PlaceholderImage];
    }else{
        [self.imageview sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BASEIMAGEURL,collectModel.IMAGEPHOTO_THUMBURL]] placeholderImage:PlaceholderImage];
    }
    self.titleLabel.text = collectModel.NAME;
    self.abstract.text = collectModel.COMMENT;
    
    //    [self.abstract setLabelSpace:1 * [UIScreen zj_screenHScale]];
    
    self.abstract.sd_layout
    .topSpaceToView(self.titleLabel, 10 * [UIScreen zj_screenHScale])
    .leftEqualToView(self.titleLabel)
    .widthIs([UIScreen zj_screenWith] - (24 +8.5 + 140) * [UIScreen zj_screenWScale])
    .heightIs([self.abstract getLableSizeWithMaxWidth:self.abstract.width].height);
    
    [self.abstract updateLayout];
    
    self.speaker.text = [NSString stringWithFormat:@"悦读者 : %@", collectModel.TEACHERSNAME];
    self.clickNumber.text = [NSString stringWithFormat:@"播放量 : %@", collectModel.CLICKRATE];
    
}


#pragma mark - Getters
#pragma mark - Getters
- (UIImageView *)imageview{
    if (_imageview == nil){
        _imageview = [UIImageView new];
        _imageview.contentMode = UIViewContentModeScaleAspectFill;
        _imageview.clipsToBounds = YES;
        _imageview.layer.borderColor = [UIColor zj_colorWithHexString:@"ededed"].CGColor;
        _imageview.layer.borderWidth = 1 * [UIScreen zj_screenWScale];
    }
    return _imageview;
}


- (UILabel *)titleLabel{
    if (_titleLabel == nil){
        _titleLabel = [UILabel new];
        _titleLabel.textColor = [UIColor textBlackColor];
        _titleLabel.font = [UIFont titleTextFont];
        _titleLabel.numberOfLines = 2;
        _titleLabel.lineSpace = 5 * [UIScreen zj_screenHScale];
        _titleLabel.characterSpace = 2 * [UIScreen zj_screenWScale];
    }
    return _titleLabel;
}
- (UILabel *)abstract{
    if (_abstract == nil){
        _abstract = [UILabel new];
        _abstract.textColor = [UIColor textBlackColor];
        _abstract.font = [UIFont titleTextFont];
        _abstract.numberOfLines = 3;
    }
    return _abstract;
}

- (UILabel *)speaker{
    if (_speaker == nil){
        _speaker = [UILabel new];
        _speaker.textColor = [UIColor textGrayColor];
        _speaker.font = [UIFont subTitleTextFont];
        
    }
    return _speaker;
}
- (UILabel *)clickNumber{
    if (_clickNumber == nil){
        _clickNumber = [UILabel new];
        _clickNumber.textColor = [UIColor textGrayColor];
        _clickNumber.font = [UIFont subTitleTextFont];
        _clickNumber.textAlignment = NSTextAlignmentRight;
    }
    return _clickNumber;
}

- (UILabel *)underline{
    if (_underline == nil){
        _underline = [UILabel new];
        _underline.backgroundColor = [UIColor viewBGGrayColor];
    }
    return _underline;
}



@end
